﻿using System;
using System.Web.UI.WebControls;
using MedicWeb.MedicService;
using Substitution = MedicWeb.MedicService.Substitution;

namespace MedicWeb.forms.Print.List {
    public partial class SubstitutionList : SessionPage {
        protected void Page_Load(object sender, EventArgs e) {
            var mainService = new MainService();
            Substitution[] substitutions = mainService.GetSubstitutionList(GetSession(), false);
            foreach (var substitution in substitutions) {
                var row = new TableRow();
                var cellEdit = new TableCell();
                var cellDelete = new TableCell();
                var cellAlias = new TableCell();
                var cellValue = new TableCell();
                var cellReplace = new TableCell();
                var cellCondition = new TableCell();
                var cellContext = new TableCell();
                cellEdit.Width = 24;
                cellEdit.Controls.Add(new HyperLink(){CssClass = "modal edit", NavigateUrl = ResolveUrl("~/forms/Print/Edit/SubstitutionEdit.aspx?id="+substitution.Id)});
                cellDelete.Controls.Add(new HyperLink() { CssClass = "delete entity", NavigateUrl = ResolveUrl("~/forms/Delete.aspx?id=" + substitution.Id + "&class="+substitution.GetType().Name) });
                cellAlias.Text = substitution.Alias;
                string value = substitution.Value;
                if (value.Length <= 8) {
                    value += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                }
                cellValue.Text = value;
                cellReplace.Text = substitution.Replace;
                cellCondition.Text = substitution.Condition;

                switch (substitution.Context) {
                    case "MedicService.Domain.Print.PrintAttestatProtocol": {
                        cellContext.Text = "Протокол аттестационной комиссии";
                        break;
                    }
                    case "MedicService.Domain.Print.PrintProfileProtocol": {
                        cellContext.Text = "Протокол профильной комиссии";
                        break;
                    }
                    case "MedicService.Domain.Print.PrintOrder": {
                        cellContext.Text = "Приказ";
                        break;
                    }
                    case "MedicService.Domain.Print.PrintExtract": {
                        cellContext.Text = "Выписка";
                        break;
                    }
                    case "MedicService.Domain.Print.PrintSertificate": {
                        cellContext.Text = "Удостоверение";
                        break;
                    }
                    default: {
                        cellContext.Text = "Не определён";
                        break;
                    }
                }
                row.Cells.Add(cellEdit);
                row.Cells.Add(cellDelete);
                row.Cells.Add(cellAlias);
                row.Cells.Add(cellValue);
                row.Cells.Add(cellReplace);
                row.Cells.Add(cellCondition);
                row.Cells.Add(cellContext);
                Table1.Rows.Add(row);
            }
        }
    }
}